package com.gexiaobao.pigeon.ui.fragment.mine.tools.activity

import android.os.Bundle
import com.gexiaobao.pigeon.app.base.BaseActivity
import com.gexiaobao.pigeon.app.ext.initClose
import com.gexiaobao.pigeon.databinding.ActivityRelatedDocumentBinding
import com.gexiaobao.pigeon.viewmodel.ProofViewModel
import okhttp3.OkHttpClient
import okhttp3.Request

/**
 * @Author      : hxw
 * @Date        : 2024/3/28 10:47
 * @Describe    : 相关单据
 */
class ActivityRelatedDocument : BaseActivity<ProofViewModel, ActivityRelatedDocumentBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        val title = intent.getStringExtra("title").toString()
        mDatabind.includeBar.toolbar.initClose(title) {
            finish()
        }
        val path = intent.getStringExtra("path").toString()

        Thread { // 创建OkHttp客户端
            val client = OkHttpClient()
            // 创建请求
            val request = Request.Builder().url(path).build()
            try {
                // 发起请求并获取响应
                val response = client.newCall(request).execute()
                // 从响应中获取HTML内容
                val htmlContent = response.body?.string()
                runOnUiThread {
                    if (htmlContent != null) {
                        mDatabind.webView.loadDataWithBaseURL(null, htmlContent, "text/html", "utf-8", null)
                    }
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }.start()
    }
}